package com.bgs.eat.memberType.controller;

import com.bgs.eat.config.CommonResult;
import com.bgs.eat.memberType.entity.MemberTypeEntity;
import com.bgs.eat.memberType.service.MemberTypeService;
import com.bgs.eat.page.PageRequest;
import com.bgs.eat.page.PageResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName MemberTypeController
 * @Description TODO 会员类型管理（后端）
 * @Author G胖
 * @Date 2022-10-12 上午 11:38
 **/

@RestController
@CrossOrigin
@RequestMapping("/memberType")
public class MemberTypeController {

    @Resource
    MemberTypeService memberTypeService;

    /**
    * @Author G胖
    * @Description 新增会员类型 （后端）
    * @Date 2022-10-12 上午 11:44
    * @Return com.bgs.eat.config.CommonResult

    */
    @PostMapping("/saveMemberType")
    public CommonResult saveMemberType(MemberTypeEntity memberTypeEntity){
        return CommonResult.ok(memberTypeService.saveMemberType(memberTypeEntity));
    }

    /**
    * @Author G胖
    * @Description 校验新增修改时会员名称是否重复（后端）
    * @Date 2022-10-12 上午 11:47
    * @Return com.bgs.eat.config.CommonResult

    */
    @GetMapping("/checkMembertypeName")
    public CommonResult checkMembertypeName(String memberName){
        return CommonResult.ok(memberTypeService.checkMembertypeName(memberName));
    }

    /**
    * @Author G胖
    * @Description 会员类型分页全查+模糊查（会员名称） 后端
    * @Date 2022-10-12 下午 02:29
    * @Return com.bgs.eat.page.PageResult

    */
    @GetMapping("/getMemberTypeByPage")
    public PageResult getMemberTypeByPage(PageRequest pageRequest,String memberName){
        return memberTypeService.getMemberTypeByPage(pageRequest,memberName);
    }

    /**
    * @Author G胖
    * @Description 修改会员类型（后端）
    * @Date 2022-10-12 下午 02:37
    * @Return com.bgs.eat.config.CommonResult

    */
    @PutMapping("/updateMemberType")
    public CommonResult updateMemberType(MemberTypeEntity memberTypeEntity){
        return CommonResult.ok(memberTypeService.updateMemberType(memberTypeEntity));
    }

    /**
    * @Author G胖
    * @Description 删除会员类型（后端）
    * @Date 2022-10-12 下午 02:38
    * @Return com.bgs.eat.config.CommonResult

    */
    @DeleteMapping("/deleteMemberType")
    public CommonResult deleteMemberType(Integer id){
        return CommonResult.ok(memberTypeService.deleteMemberType(id));
    }

    /**
    * @Author G胖
    * @Description 会员价格管理查询会员类型 （后端）
    * @Date 2022-10-12 下午 03:46
    * @Return

    */
    @GetMapping("/getSelectMemberType")
    public CommonResult getSelectMemberType(){
        return CommonResult.ok(memberTypeService.getSelectMemberType());
    }

    /**
    * @Author G胖
    * @Description 查询会员id （后端）
    * @Date 2022-10-12 下午 04:43
    * @Return com.bgs.eat.config.CommonResult

    */
    @GetMapping("/getEatMemberId")
    public CommonResult getEatMemberId(String memberName){
        return CommonResult.ok(memberTypeService.getEatMemberId(memberName));
    }
}
